<?php if (!defined('THINK_PATH')) exit();?>	<!DOCTYPE html>
	<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>新疆车管家后台</title>
		<link rel="stylesheet" href="/Public/layui/css/layui.css">
		<style type="text/css">
			body{margin: 10px;}
				.demo-carousel{height: 200px; line-height: 200px; text-align: center;
			}
			#tree{
				width:300px; padding:20px;
			}
			#tree li i{
				color:#1E9FFF;
			}

		</style>
	</head>
	<body>
		 <blockquote class="layui-elem-quote">
			<div class="layui-inline">
				<label class="layui-form-label">搜索名称</label>
				<div class="layui-input-inline">
					<input type="text" class="layui-input" placeholder="搜索名称" id="like">
				</div>
				<button class="layui-btn layui-input-inline" onclick="search()">搜索</button>
				<a class="layui-btn layui-input-inline" href="#" onclick="add_user()">添加管理员</a>
			</div>
		</blockquote>
		<fieldset class="layui-elem-fied site-demo-button"> 
			<legend>管理员信息列表</legend>
			<table id="demo" lay-filter="demo"></table>
		</fieldset>

		<!-- 添加管理员 -->
	  <form class="layui-form" id="adduser" style="display:none;">
		<div class="layui-form-item" style="margin-top: 30px;">
			<label class="layui-form-label">账号:</label>
			<div class="layui-input-block">
			  <input type="text" name="mobile" placeholder="请输入账号" autocomplete="off" class="layui-input">
			</div>
		 </div>
		 <div class="layui-form-item">
			<label class="layui-form-label">密码:</label>
			<div class="layui-input-block">
			  <input type="text" name="pwd" placeholder="请输入密码" autocomplete="off" class="layui-input">
			</div>
		 </div>
		<div class="layui-form-item">
			<div class="layui-input-block">
			  <button class="layui-btn" lay-submit lay-filter="insert">立即提交</button>
			  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	  </form>

	  <!-- 编辑管理员 -->
	  <form class="layui-form" id="edituser" style="display:none;">
		<div class="layui-form-item" style="margin-top: 30px;">
			<label class="layui-form-label">账号:</label>
			<div class="layui-input-block">
			  <input type="text" id="id" name="id" style="display: none;" placeholder="请输入账号" autocomplete="off" class="layui-input">
			  <input type="text" id="editmobile" name="editmobile" placeholder="请输入账号" autocomplete="off" class="layui-input">
			</div>
		 </div>
		 <div class="layui-form-item">
			<label class="layui-form-label">密码:</label>
			<div class="layui-input-block">
			  <input type="password" id="editpwd" name="editpwd" placeholder="请输入密码" autocomplete="off" class="layui-input">
			</div>
		 </div>
		<div class="layui-form-item">
			<div class="layui-input-block">
			  <button class="layui-btn" lay-submit lay-filter="edit">立即提交</button>
			  <button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	  </form>
		<script src="/Public/layui/layui.all.js"></script>
		<script type="text/javascript">
			var like = "";
			var add_window=0;
			var edit_window=0;
			var table = layui.table;
			table.render({
				elem: '#demo',
				url:"/Admin/Admin/get_all_admin_list",
				height: 500,
				width:1550,
				cellMinWidth:80,
				page:true,
				limit:10,
				loading:true,
				text: {    
					none: '暂无相关数据' //自定义文本，如空数据时的异常提示等默认：无数据。
				},
				cols: [[ //表头参数
					{field:'id', title:'ID', width: 80},
					{field:'mobile', width:100, title: '手机号'},
					{fixed: 'right', width:200, align:'center', toolbar: '#barDemo'} //设置表头的删改查
				]],
				response: {				//用于对返回的数据格式的自定义
					statusName:'code', //数据状态的字段名称，默认：code
					statusCode:200,	   //成功的状态码，默认：0
					countName:'total', //数据总数的字段名称，默认：count
					dataName:'data'   //数据列表的字段名称，默认：data
				},
			});

			//所有渲染方式渲染表格重载 这里的表格重载是指对表格重新进行渲染，包括数据请求和基础参数的读取(多用于搜索)
			function search(){
				like = $('#like').val();
				//执行重载 重载默认执行当前控制器index方法
				table.reload('demo', {
					where: {  
						like: like  //设定异步数据接口的额外参数
					},
					page: {
						curr: 1 //重新从第 1 页开始
					}
			  });

			}

		//添加管理员窗口
		function add_user(){
			add_window=layer.open({
				type:1,
				content:$('#adduser'),
				area: ['500px', '300px']

			});
		}	

		//添加管理员提交
		form.on('submit(insert)', function(data){
			ajax('/Admin/Admin/question_insert',data.field,function(ret){
				layer.msg('添加成功！');
				layer.close(add_window);
				location.href="/Admin/Admin/index";
			})
			return false;
		});

		//编辑管理员提交
		form.on('submit(edit)', function(data){
			ajax('/Admin/Admin/question_edit',data.field,function(ret){
				layer.msg('编辑成功！');
				layer.close(edit_window);
				location.href="/Admin/Admin/index";
			})
			return false;
		});

		//点击编辑按钮
		table.on('tool(demo)', function(obj){ 
			if (obj.event == "edit") {
				$('#id').val(obj.data.id);
				$('#editmobile').val(obj.data.mobile);
				$('#editpwd').val(obj.data.pwd);
				edit_window=layer.open({
					type:1,
					content:$('#edituser'),
					area: ['500px', '300px']

				});
			}

			if (obj.event == "del") {
				var index = layer.confirm('删除后无法恢复，确认删除?', {
					icon: 3, 
					title:'温馨提示'
				}, function(index){
					ajax('/Admin/Admin/question_del',{
						"id":obj.data.id
					},function(res){
						obj.del();  //删除对应行（tr）的DOM结构
						layer.close(index);
						layer.msg(res.msg);
					})
					
				});
			}
			console.log(obj);
		});

		</script>
		<script type="text/html" id="barDemo">
			<div class="layui-btn-group">
				<button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="edit">编辑</button>
				<button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="del">删除</button>
			</div>
		</script>
	</body>
	</html>\